export default {
    install(Vue, options) {
        // 排序
        Vue.prototype.baseCompareFun = function(array, key) {
            return array.sort(function(a, b) {
                var x = a[key]
                var y = b[key]
                return x > y ? -1 : x < y ? 1 : 0
            })
        };
        // 差集
        Vue.prototype.baseDifference = function(arr1, arr2, typeName) {
            return Object.values(
                arr1.concat(arr2).reduce((acc, cur) => {
                    if (
                        acc[cur[typeName]] &&
                        acc[cur[typeName]][typeName] === cur[typeName]
                    ) {
                        delete acc[cur[typeName]];
                    } else {
                        acc[cur[typeName]] = cur;
                    }
                    return acc;
                }, {})
            );
        };
        // 跳转route
        Vue.prototype.basePushFun = function(val = "/", obj) {
            this.$router.push({
                path: val,
                query: {
                    ...obj
                }
            });
        };
    }
};